package com.cy.pj.eiems.controller;

import java.rmi.ServerException;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cy.pj.eiems.entity.SysStudent;
import com.cy.pj.eiems.service.SysStudentService;
import com.cy.pj.eiems.service.impl.UserServiceImpl;
import com.cy.pj.eiems.vo.JsonResult;


@RequestMapping("/user/")
@Controller
public class UserPageController {
	@Autowired
	private UserServiceImpl userServiceImpl;
	@Autowired
	private SysStudentService service;
	@ResponseBody
	@RequestMapping("dologin")
	public JsonResult doLogin(String username,String password) {
		userServiceImpl.findUser(username, password);
		return new JsonResult(1);
	}
	/*
	 * @RequestMapping("/doregist")
	 * 
	 * @ResponseBody public String doRegist(User user,Map<String,Object> map) {
	 * userServiceImpl.insertUser(user.getUsername(),user.getPassword());
	 * map.put("set","注册成功"); return "注册成功"; }
	 */
	@RequestMapping(value = "doLogon",method = RequestMethod.GET)
	//@ResponseBody
	public String doLogon(
			@Param("studentName") String studentName,
			@Param("username")String username,
			@Param("password")String password,
			@Param("passwordConfirm")String passwordConfirm,
			@Param("phoneNumber")Integer phoneNumber,
			@Param("profession")String profession) throws Exception {

		System.out.println(studentName);//测试用
		System.out.println(username);
		System.out.println(password );
		System.out.println(passwordConfirm);
		System.out.println(phoneNumber);
		System.out.println(profession);	
		System.out.println(password.equals(passwordConfirm));
		SysStudent student = new SysStudent();

		student.setMobile(phoneNumber);
		student.setPassword(passwordConfirm);
		student.setStudentName(studentName);
		student.setUsername(username);
		
		if (!password.equals(passwordConfirm)) {
			throw new ServerException("两次密码不一样");
		}
		if(profession.equals("教师")) {

		}
		service.saveStudentObject(student);

		
		System.out.println("controller运行结束");
		return "login";




		//		if ("教师".equals(profession)) {
		//			int teacher = dao.logonTeacher(userInfo);
		//			if (teacher!=1) {
		//				throw new IllegalArgumentException("注册失败");
		//			}
		//		}
		//		int student = dao.logonStudent(userInfo);
		//		if (student!=1) {
		//			throw new IllegalArgumentException("注册失败");
		//		}
		//		return new JsonResult("注册成功");

		//
		//		Map<String, String> userInfo=new HashedMap();
		//		userInfo.put("name",name );
		//		userInfo.put("mobile", phoneNumber);
		//		userInfo.put("username", username );
		//		if (!password.equals(passwordConfirm)) {
		//			throw new ServerException("两次密码不一样");
		//		}
		//		userInfo.put("password", passwordConfirm);		

	}
}
